package com.server.http.handler.impl;

import com.server.conditionenum.HttpReturnStatus;
import com.server.db.DataBaseManager;
import com.server.http.handler.HttpHandler;
import com.server.http.request.HttpRequestMessage;
import com.server.http.response.HttpResponseMessage;
import com.server.mine.net.HttpProtocol;
import com.server.tools.AppData;

/**
* @author	李小布
* @email	397554852@qq.com
* @version	创建时间：2018年9月27日 下午3:27:50
*/
public class GetUID extends HttpHandler{
	// -1上传参数错误;-2APP不存在;-3数据库异常;-4未知错误
	@Override
	public void handle(HttpRequestMessage request, HttpResponseMessage response) {
		int failMsg = 0;
		String unionid = request.getParameter("unionid");
		long appid = 0;
		long uid = 0;
		if(unionid == null || "".equals(unionid)) {
			failMsg = -1;
		}else {
			try {
				appid = Long.parseLong(request.getParameter("appid"));
				if(AppData.appMap.containsKey(appid)) {
					uid = DataBaseManager.GetInstance().GetUID(unionid,appid);
					if(uid < 0) {
						failMsg = (int)uid;
					}
				}else {
					failMsg = -2;
				}
			} catch (Exception e) {
				failMsg = -1;
			}
			
		}

		if(failMsg == 0) {
			SetReturnData(response,uid,HttpProtocol.GETUID,HttpReturnStatus.Successed);
		}else {
			SetReturnData(response,failMsg,HttpProtocol.GETUID,HttpReturnStatus.Failed);
		}
	}
}
